<template>
	<view class="cu-modal" :class="visible ? 'show' : ''">
		<view class="cu-dialog">
			<view class="cu-bar bg-white justify-end">
				<view class="content">操作结果</view>
			</view>
			<view class="padding-sm" v-for="item in content" :key="item.id">{{ item.text }}</view>
			<view class="cu-bar bg-white">
				<!-- <view class="action margin-0 flex-sub  solid-left" @tap="cancelClick">撤销发送</view> -->
				<view class="action margin-0 flex-sub text-blue solid-left" @tap="okClick">确定</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	props: {
		visible: {
			type: Boolean,
			default: false
		},
		msg: {
			type: String,
			default: ''
		}
	},
	data() {
		return {
			content: []
		};
	},
	watch: {
		msg: {
			deep: true,
			immediate: true,
			handler(val, oldVal) {
				if (val == '') {
					this.content = [];
				} else if (val != oldVal) {
					try {
						let arr = val.split('@');
						let arr2 = [];
						if (arr.length > 1) {
							arr.forEach((e, i) => {
								let str = e.replace(/<[^>]+>/g, '');
								if (!str.includes('撤销本次发送')) {
									arr2.push({
										text: str,
										id: i
									});
								}
							});
							this.content = arr2;
						} else if (arr.length > 0) {
							this.content = arr;
						} else {
							this.content = [];
						}
					} catch (e) {
						//TODO handle the exception
						uni.showModal({
							title: '出错了',
							content: '解析结果出错',
							showCancel: false,
							success() {}
						});
					}
				}
			}
		}
	},
	methods: {
		hideModal() {
			this.$emit('close-modal');
		},
		cancelClick() {
			this.$emit('cancel-click');
		},
		okClick() {
			this.$emit('ok-click');
		}
	}
};
</script>

<style></style>
